﻿using System;
using System.Linq;
using FluentAssertions;
using RandomKatas.Kata02;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace RandomKataTests
{
    [TestClass]
    public class BinaryChopTest
    {
        [TestMethod]
        public void TestStrategy1()
        {
            _Test(GetToDaBinary.Choppa("strategy1"));
        }

        [TestMethod]
        public void TestStrategy2()
        {
            _Test(GetToDaBinary.Choppa("strategy2"));
        }

        [TestMethod]
        public void TestStrategy3()
        {
            _Test(GetToDaBinary.Choppa("strategy3"));
        }

        [TestMethod]
        public void TestStrategy4()
        {
            _Test(GetToDaBinary.Choppa("strategy4"));
        }

        [TestMethod]
        public void TestStrategy5()
        {
            _Test(GetToDaBinary.Choppa("strategy5"));
        }

        private void _Test(IBinaryChop chopper)
        {
            chopper.Chop(3, new int[0]).Should().Be(-1);
            chopper.Chop(3, new[] { 1 }).Should().Be(-1);
            chopper.Chop(1, new[] { 1 }).Should().Be(0);

            var arr = new[] { 1, 3, 5 };
            var notArr = new[] { 0, 2, 4, 6 };
            _TestArrs(chopper, arr, notArr);

            arr = new[] { 1, 3, 5, 7, 9, 11, 13 };
            notArr = new[] { 0, 2, 4, 6, 8, 10, 12, 14 };
            _TestArrs(chopper, arr, notArr);
        }

        private void _TestArrs(IBinaryChop chopper, int[] arr, int[] notArr)
        {
            for (int idx = 0; idx < arr.Length; ++idx)
                chopper.Chop(arr[idx], arr).Should().Be(idx, "because {0} should be found", arr[idx]);

            for (int idx = 0; idx < notArr.Length; ++idx)
                chopper.Chop(notArr[idx], arr).Should().Be(-1, "because {0} should not be found", notArr[idx]);
        }
    }
}
